package com.example.demo.mapper;

import com.example.demo.dto.SearchInfo;
import com.example.demo.entity.Chukujilu;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository()
public interface Chukujilu_Mapper extends BaseMapper<Chukujilu>{

	@Select("SELECT Chukujilu.*, cangku.chanpinname AS shangpinname, Danweixinxi.danweiname AS danweiname, Zhigong.name AS zhigongname, Yunshugongju.chepaihao AS chepaihao "
			+ " FROM Chukujilu "
			+ " JOIN cangku ON Chukujilu.shangpinid = cangku.id "
			+ " JOIN Danweixinxi ON Chukujilu.danweiid = Danweixinxi.id "
			+ " JOIN Zhigong ON Chukujilu.zhigongid = Zhigong.id "
			+ " JOIN Yunshugongju ON Chukujilu.yunshugongjuid = Yunshugongju.id "
			+ " ${where} ${limitstr}")
	public List<Chukujilu> select(SearchInfo info);


	@Select("SELECT COUNT(1) FROM Chukujilu " +
			" JOIN cangku ON Chukujilu.shangpinid = cangku.id" +
			" JOIN Danweixinxi ON Chukujilu.danweiid = Danweixinxi.id" +
			"  JOIN Zhigong ON Chukujilu.zhigongid = Zhigong.id  " +
			" JOIN Yunshugongju ON Chukujilu.yunshugongjuid = Yunshugongju.id " +
			" ${where}")
	public long selectCount(SearchInfo info);
	
	@Insert("INSERT INTO Chukujilu (shangpinid, danweiid, zhigongid, yunshugongjuid, caozuoshuliang,chukutime,bufa) VALUES (#{shangpinid}, #{danweiid}, #{zhigongid}, #{yunshugongjuid}, #{caozuoshuliang}, #{chukutime},#{bufa})")
	public void insert(Chukujilu Chukujilu);
	
	@Update("UPDATE Chukujilu SET shangpinid = #{shangpinid}, danweiid = #{danweiid}, "
	        + " zhigongid = #{zhigongid}, yunshugongjuid = #{yunshugongjuid} , caozuoshuliang = #{caozuoshuliang} , chukutime = #{chukutime} ,bufa=#{bufa} WHERE id = #{id}")
	public void update(Chukujilu Chukujilu);
	
	
	@Delete("DELETE FROM Chukujilu WHERE id = #{id}")
	public void delete(int id);
	
	@Select("SELECT * FROM Chukujilu WHERE id = #{id}")
	public Chukujilu selectById(int id);
	
}
